package com.example.news.controller;


import annotation.RequireRoles;
import com.example.news.service.NewscommentServiceImpl;
import entity.PageParam;
import entity.Rsp;
import entity.Newscomment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 模块接口
 */

@RestController
@Api(value = " 模块接口",description=" 模块接口")
public class NewscommentController {

    private static final Logger log = LoggerFactory.getLogger(NewscommentController.class);

    @Autowired
    NewscommentServiceImpl newscommentService;



    @PostMapping("/searchSomeNewscommentByPage")
    @RequireRoles(roles = {"admin","super_admin","news_admin","news_editor"},index = 2)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Newscomment> newscommentPageParam,
                                @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        log.info("userId:{}",userId);
        log.info("roleId:{}",roleSign);

        return Rsp.success(newscommentService.searchSomeByPage(newscommentPageParam));
    }


    @RequireRoles(roles = {"super_admin","admin","news_admin"},index = 2)
    @PostMapping("/addOneNewscomment")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        newscomment.setCreateUserId(userId);
        return newscommentService.addOne(newscomment);
    }


    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteOneNewscommentTrue")
    @ApiOperation("通过ID物理删除")
    public Rsp deleteOneNewscommentTrue(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        return newscommentService.deleteOneTrue(newscomment.getId());
    }

    @RequireRoles(roles = {"super_admin","admin","news_admin","news_editor"},index = 2)
    @PostMapping("/updateNewscomment")
    @ApiOperation("动态修改")
    public Rsp updateNewscomment(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){


		newscomment.setUpdateUserId(userId);
        return newscommentService.update(newscomment);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteNewscommentLogical")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteNewscommentLogical(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscommentService.deleteLogical(newscomment);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/recoverNewscommentLogical")
    @ApiOperation("逻辑恢复")
    public Rsp recoverNewscommentLogical(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscommentService.recoverLogical(newscomment);
    }


    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteBatchNewscommentTrue")
    @ApiOperation("批量物理删除")
    public Rsp deleteBatchNewscommentTrue(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscommentService.deleteBatchTrue(ids);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteBatchNewscommentLogical")
    @ApiOperation("批量逻辑删除")
    public Rsp deleteBatchNewscommentLogical(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscommentService.deleteBatchLogical(ids);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteSomeNewscommentLogicalByCondition")
    @ApiOperation("条件逻辑删除")
    public Rsp deleteSomeNewscommentLogicalByCondition(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscommentService.deleteSomeLogicalByCondition(newscomment);
    }

    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteSomeNewscommentTrueByCondition")
    @ApiOperation("条件物理删除")
    public Rsp deleteSomeNewscommentTrueByCondition(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newscommentService.deleteSomeTrueByCondition(newscomment);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/getNewscommentById")
    @ApiOperation("通过ID获取")
    public Rsp getNewscommentById(@RequestBody Newscomment newscomment, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return Rsp.success(newscommentService.getOneById(newscomment.getId()));
    }


}
